package org.judo.admin;

import org.judo.controller.PageController;
import org.judo.database.Database;
import org.judo.propertyobject.PropertyObject;
import org.judo.security.SecurityManager;

import java.util.*;
import org.judo.controller.DefaultAction;

public class SiteResourceController extends PageController 
{
	private Database sysDB ;
	private String siteresourceid ;
	private String url ;
	private int id ;
	private ArrayList results = new ArrayList();

	public void detailSiteResource() throws Exception
	{
		PropertyObject obj = sysDB.find(parse("select * from SITE_RESOURCE where SITERESOURCEID = ${id}"));
		copyProps(obj);
	}
	
	public void insertSiteResource() throws Exception
	{
		showPage("/admin/Site_resource_controller/display_site_resource.do");
		SiteResource obj = new SiteResource();
		obj.copyProps(this);
		sysDB.insert("SITE_RESOURCE",obj);
		SecurityManager.addProtectedURL(url);
			
	}
	
	public void editSiteResource() throws Exception
	{
		PropertyObject obj = sysDB.find(parse("select * from Site_resource where SITERESOURCEID = ${id}"));
		copyProps(obj);
	}

	public void updateSiteResource() throws Exception
	{
		showPage("/admin/Site_resource_controller/display_site_resource.do");
		SiteResource obj = (SiteResource)sysDB.find(SiteResource.class,id);
		SecurityManager.removeProtectedURL(obj.getUrl());
		obj.copyProps(this);
		sysDB.update("SITE_RESOURCE",obj);
		SecurityManager.addProtectedURL(url);
	}

	@DefaultAction
	public void displaySiteResource() throws Exception
	{
		results = (ArrayList)sysDB.query("select * from SITE_RESOURCE");
	}

	public void deleteSiteResource() throws Exception
	{
		SiteResource obj = (SiteResource)sysDB.find(SiteResource.class,id);
		SecurityManager.removeProtectedURL(obj.getUrl());
		
		showPage("/admin/Site_resource_controller/display_site_resource.do");
		sysDB.delete(this,"delete from SITE_RESOURCE where SITERESOURCEID = ${id}");
	}
	
	public void setSiteresourceid(String siteresourceid) 
	{
		this.siteresourceid = siteresourceid;
	}

	public String getSiteresourceid() 
	{
		return this.siteresourceid;
	}

	public void setUrl(String url) 
	{
		this.url = url;
	}

	public String getUrl() 
	{
		return this.url;
	}

	public void createSiteResource() throws Exception
	{
	}
	
	public void setId(int id) 
	{
		this.id = id;
	}

	public int getId() 
	{
		return this.id;
	}

	public void setResults(ArrayList results) 
	{
		this.results = results;
	}

	public ArrayList getResults() 
	{
		return this.results;
	}
}
